import data from "./data";

interface OptionState {
  root: HTMLElement;
  openSubChildren?: boolean
}

// 类 泛型
class Tree {
  // 属性属性
  private list: typeof data;
  option: OptionState
  constructor(list: typeof data, option: OptionState) {
    // 默认参数
    const defaultOption = {
      openSubChildren: true
    }
    // 合并参数
    option = Object.assign(defaultOption, option)
    this.option = option
    this.list = list;
  }
  // 初始化
  init() {
    this.render(this.list)
  }
  render(list: typeof data) {
    this.option.root.innerHTML = `
      <ul>
        ${list.map(v => {
          return `<li>${v.name}</li>`
        })}
      </ul>
    `
  }
  // 私有方法
  private sayList() {
    console.log(this.list);
  }
}

new Tree(data, {
	root: document.querySelector('#root') as HTMLElement
});
